<!-- 销售 -->
<template>
	<view class="content">
		<expressSheet :orderData="orderData" type="into" :aimType="type"></expressSheet>
		<view class="" style="height: 88rpx;"></view>
		<view class="footer" @click="handleSweep">{{submit}}</view>
	</view>
</template>

<script>
	import expressSheet from '../../../components/express_sheet.vue'

	export default {
		data() {
			return {
				orderData: {
					"sku_images": [],
					"color": "",
					"size": "",
					"material_quality": "",
					"store_name": "",
					"goods_title": "",
					"skc_number": "",
					"goods_code": "",
					"qrcode_url": "",
					"barcode": "",
					"ctime": "",
					"goods_number": 0,
					"sku_nuber": ""
				},
				submit: this.$t("sweep") + ' - ' + this.$t("index.into"),
				type: 0,
				optionType: true, // 
				submitType: true, // 防抖
				goods_code: "", // 
			}
		},
		components: {
			expressSheet
		},

		onLoad(option) {
			console.log(option, 'option');
			if (option.text) {
				uni.setNavigationBarTitle({
					title: option.text
				})
			}
			if (option.value) this.type = option.value
		},
		onShow() {
			let that = this

			uni.$on('isRefresh', async function(data) {
				console.log('监听到事件来自返回的参数：' + data);

				// data =
				// 	"https://africaadmin.lastinglight.cn/cxboiZCapj.php/deliverys/fahuo/returnJson?goods_code=PC20240808931256"

				const [err, res] = await uni.request({
					// url: data.replace("http", "https"),
					url: data
				});

				that.goods_code = data.split("=")[1]
				if (res.data.code == 200) {
					that.orderData = res.data.data[0]
					that.submit = this.$t("verify") + ' - ' + this.$t("index.into")
					that.optionType = false
				}
			})
		},
		methods: {
			// 扫码事件
			handleSweep() {
				let that = this
				let userInfo = uni.getStorageSync("userInfo")
				let standing = uni.getStorageSync("standing")

				if (this.optionType && this.submitType) {
					uni.navigateTo({
						url: "/pages/qrcode/index",
					})
				} else {
					if (!this.submitType) return

					this.submitType = false
					if (standing == 2) {
						console.log("仓库销售订单")
						that.httpPost("/api/RemovePackage/storeSaleRemove",
							`store_id=${userInfo.id}&goods_code=${that.goods_code}`)
					} else if (standing == 3) {
						console.log("店铺销售出库接口");
						that.httpPost("/api/RemovePackage/shopSaleRemove",
							`shop_id=${userInfo.id}&goods_code=${that.goods_code}`)
					}
				}
			},
			// post请求函数
			httpPost(url = "", data = {}) {
				url = url.replace("/api", this.$http)
				this.$ajax(url, "POST", data, (response) => {
					let res = JSON.parse(response)
					if (res.code == 200) {
						console.log(res, 'res');
						this._toastBack(res.msg)
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none",
							success: () => {
								setTimeout(() => {
									uni.navigateBack()
									this.submitType = !this.submitType
								}, 1200)
							}
						})
					}
				})
			},
			// 提示语+返回上一页
			_toastBack(msg) {
				uni.showToast({
					title: msg,
					icon: "none",
					success: () => {
						setTimeout(() => {
							uni.navigateBack()
							this.submitType = !this.submitType
						}, 1200)
					}
				})
			},
			// 预览图片
			previewImage(index) {
				uni.previewImage({
					urls: this.orderData.sku_images,
					current: index
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content-box {
		width: 100vw;
		background: #fff;
		padding: 60rpx 34rpx;
	}

	.content-box .item:last-child {
		border: none;
	}

	.item {
		height: 124rpx;
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #DFE1E6;
		font-size: 32rpx;
	}

	.item-title {
		color: #15161A;
		width: 200rpx;
		font-weight: 700;
	}

	.item-img {
		width: 80rpx;
		height: 80rpx;
		margin-right: 8rpx;
	}

	.item-tag {
		color: #C9CACC;
	}

	.footer {
		width: 100%;
		line-height: 88rpx;
		background: #FF3C3F;
		color: #fff;
		position: fixed;
		bottom: 0;
		text-align: center;
	}
</style>